home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
8bitfiles.net/archives
/
archives.tar
/
archives
/
genie-commodore-file-library
/
C64Toolkit
/
FSERIAL.SDA
/
FAST SERIAL.SRC
< prev
next >
Wrap
Text File
|
2019-04-13
|
22KB
|
707 lines
;*********************************************************
;
; ╞AST SERIAL ┬╒╙ ROUTINES FOR 1541/71
;
; ╫RITTEN ┬Y ╥OBERT ┴. ╙TOERRLE (A.K.A. ═┴╠┴╦┴╔)
;
; ┴UGUST 29, 1988
;
; ╨OWER ┴SSEMBLER FORMAT
;
;**********************************************************
;
;╘HIS PACKAGE IS INTENDED TO INSTRUCT PROGRAMMERS WITH A
;REASONABLE PROFICIENCY IN ASSEMBLY LANGUAGE IN THE
;IMPLEMENTATION OF FAST SERIAL COMMUNICATION ROUTINES FOR
;THE 1571/41. ╘HE AUTHOR DOES NOT CLAIM THAT THESE ARE THE
;FASTEST TECHNIQUES.
;
;╨LEASE NOTE THAT THE ROUTINES PROVIDED DO NOT CONSTITUTE
;A COMPLETE DISK OPERATING SYSTEM BUT PROVIDE ONLY A MEANS
;FOR ACCESSING SPECIFIC TRACKS AND SECTORS ON THE DISK.
;╘HE ROUTINES CAN BE EASILY ACTIVATED AND DEACTIVATED AT
;WILL AND DO NOT AFFECT OTHER DEVICES ON THE SERIAL BUS.
;
;┬EST SPEED RESULTS ARE OBTAINED WHEN THE TEXT SCREEN IS
;BLANKED DURING FAST DATA TRANSFERS, AND THESE ROUTINES ARE
;SET UP TO BLANK THE SCREEN WHENEVER A DRIVE'S FAST ROUTINE
;IS ACTIVE. ┘OU WILL FIND NOTES WHERE APPROPRIATE ON
;CONFIGURING THE ROUTINES TO WORK WITH THE SCREEN ON.
;
;----------------------------------------------------------
;╙TANDARD ╦ERNAL ROUTINE EQUATES
;----------------------------------------------------------
;
SETLFS = $FFBA
SETNAM = $FFBD
OPEN = $FFC0
CLOSE = $FFC3
CHKIN = $FFC6
CHKOUT = $FFC9
CLRCHN = $FFCC
CHRIN = $FFCF
CHROUT = $FFD2
;
;----------------------------------------------------------
;├ONSTANTS
;----------------------------------------------------------
;
DRIVESTART = $0500 ;╫HERE ═╠ WILL RESIDE IN DRIVE
; ╔F THIS IS CHANGED, THE ╒X COMMAND
; IN ┴├╘╔╓┴╘┼╞ MUST ALSO BE CHANGED!
CIA = $DD00 ;├OMPUTER INTERFACE TO SERIAL BUS
;
;----------------------------------------------------------
;╙TORAGE USED BY THIS PROGRAM
;----------------------------------------------------------
;
STORAGE = $C800 ;╙TART OF EXTERNAL STORAGE
FASTBUF = STORAGE ;╚OLDS BLOCK RECEIVED/TO BE SENT
VAR = STORAGE+256 ;╙TART OF EXTERNAL VARIABLES
FTRACK = VAR ;├URRENT TRACK
FSECTOR = VAR+1 ;├URRENT SECTOR
BLOCKCNT = VAR+2 ;╬UMBER OF 32 BYTE CHUNKS TO SEND
;
;----------------------------------------------------------
;┌ERO-PAGE STORAGE USED BY THIS PROGRAM
;----------------------------------------------------------
;
APTR = $FB ;╨OINTS INTO DRIVE CODE IN 64
BPTR = $FD ;╨OINTS INTO DRIVE ╥┴═
BVALUE = $FB ;┬YTE RECEIVED FROM DRIVE. ═╒╙╘ BE
;┌╨ FOR TIMING PURPOSES!
;
;----------------------------------------------------------
;╨ROGRAM START ADDRESS AND JUMP TABLE TO MAJOR ROUTINES
;----------------------------------------------------------
;
.ORG $C000 ;╨ROGRAM START ADDRESS. ═AY BE
; RELOCATED AT WILL
;
JMP PREPAREF ;╙END ═╠ ROUTINES TO DRIVE
JMP ACTIVATEF ;┴CTIVATE FAST ROUTINES IN DRIVE
JMP RELEASEF ;─EACTIVATE FAST ROUTINES
JMP READF ;╥EAD A BLOCK FROM DRIVE
JMP WRITEF ;╫RITE A BLOCK TO DRIVE
JMP GETF ;╟ET A BYTE FROM DRIVE
JMP SENDF ;╙END A BYTE TO DRIVE
;
;----------------------------------------------------------
;├OMPUTER-RESIDENT ROUTINES
;----------------------------------------------------------
;
;╨╥┼╨┴╥┼╞ SENDS ═╠ ROUTINES TO THE DRIVE TO ACCOMPLISH THE
;FAST SERIAL BUS TRANSFERS, BUT DOES NOT ACTIVATE THE
;ROUTINES. ╘HAT ALLOWS SEVERAL DRIVES TO BE ACCESSED USING
;THE FAST ROUTINES BY INITIALIZING THEM EACH USING THIS
;ROUTINE.
;
;┬┼╞╧╥┼ ├┴╠╠╔╬╟: .┴ SHOULD CONTAIN DEVICE NUMBER (8-11)
; OF DRIVE BEING INITIALIZED.
;
;╘HE STANDARD ═-╫ COMMAND IS USED TO SEND THE CODE TO
;THE DRIVE IN 32 BYTE CHUNKS. ╘HE CORRECT AMOUNT OF CODE
;WILL BE SENT REGARDLESS OF WHETHER THE LENGTH OF THE
;DRIVE CODE IS CHANGED, SO FEEL FREE TO MAKE ADDITIONS/
;DELETIONS TO THE DRIVE PORTION OF THIS SOURCE. ╨LEASE
;NOTE THAT THIS ROUTINE DOES NOT PRESERVE ANY REGISTERS.
;
PREPAREF = *
;
TAX
LDA #7
LDY #15
JSR SETLFS
LDA #0
JSR SETNAM
JSR OPEN ;╧PEN AN ERROR CHANNEL TO DEVICE
;
LDA #<DRIVECODE ;╙ET UP ┴╨╘╥ TO POINT TO DRIVE
STA APTR ; CODE IN COMPUTER (APPENDED TO
LDA #>DRIVECODE ; THE END OF THIS FILE)
STA APTR+1
LDA #<DRIVESTART ;┬╨╘╥ WILL POINT TO CORRESPONDING
STA BPTR ; ADDRESS IN DRIVE ╥┴═
LDA #>DRIVESTART
STA BPTR+1
LDA #ENDDRIVECODE-DRIVECODE/32+1
STA BLOCKCNT ;╬UMBER OF 32 BYTE CHUNKS TO SEND
;
PRP1 LDX #7 ;╙END AN ═-╫ COMMAND TO DRIVE
JSR CHKOUT
LDA #"M"
JSR CHROUT
LDA #"-"
JSR CHROUT
LDA #"W"
JSR CHROUT
LDA BPTR ;╙END ADDRESS IN DRIVE ╥┴═
JSR CHROUT
LDA BPTR+1
JSR CHROUT
LDA #32 ;╬UMBER OF BYTES TO BE SENT
JSR CHROUT
LDY #0
- LDA (APTR),Y
JSR CHROUT ;╙END 32 BYTES TO DRIVE
INY
CPY #32
BNE -
LDA APTR ;╙ET UP POINTERS FOR NEXT
CLC ; 32 BYTE CHUNK
ADC #32
STA APTR
BCC +
INC APTR+1
+ LDA BPTR
CLC
ADC #32
STA BPTR
BCC +
INC BPTR+1
+ JSR CLRCHN
;
DEC BLOCKCNT ;═ORE CHUNKS TO SEND?
BNE PRP1 ; ┘ES - GO BACK AND SEND ANOTHER
;
JSR CLRCHN ; ╬O - ├LOSE FILE AND EXIT
LDA #7
JSR CLOSE
RTS
;
;┴├╘╔╓┴╘┼╞ IS USED TO ACTIVATE THE FAST SERIAL ROUTINES IN
;A DRIVE. ╨╥┼╨┴╥┼╞ MUST ALREADY HAVE BEEN CALLED FOR THE
;DRIVE, OR THE DRIVE WILL LIKELY CRASH! ╘HE SERIAL BUS WILL
;BE SEIZED BY THE DRIVE, SO WHILE FAST ROUTINES ARE ACTIVE
;IN ANY DRIVE, ╬╧ OTHER DRIVE OR SERIAL PERIPHERAL MAY BE
;USED. ═ULTI-DRIVE OPERATIONS ARE EASILY ACCOMPLISHED BY
;REPEATEDLY USING ┴├╘╔╓┴╘┼╞ AND ╥┼╠┼┴╙┼╞ FOR EACH DRIVE
;EACH TIME IT IS ACCESSED. ╬OTE THAT WHEN THE FAST SERIAL
;ROUTINES ARE NOT ACTIVE IN A DRIVE, NORMAL ─╧╙ COMMANDS
;MAY BE SENT TO THAT DRIVE. ╚OWEVER, KEEP IN MIND THAT
;THE DRIVE CODE (KEPT IN BUFFER 2 @ $500) MIGHT BE
;OVERWRITTEN, AND THUS ╨╥┼╨┴╥┼╞ SHOULD BE CALLED AGAIN
;FOR THAT DRIVE BEFORE ANY FURTHER FAST COMMUNICATION.
;
;┬┼╞╧╥┼ ├┴╠╠╔╬╟ ╘╚╔╙ ╥╧╒╘╔╬┼: .┴ = ─EVICE NUMBER (8-11)
;╧╬ ╥┼╘╒╥╬: ╬O REGISTERS ARE PRESERVED!
;
ACTIVATEF = *
;
TAX
LDA #7
LDY #15
JSR SETLFS
LDA #0
JSR SETNAM
JSR OPEN ;╧PEN AN ERROR CHANNEL TO DRIVE
;
LDA $D011 ;╘HESE THREE LINES BLANK THE SCREEN
AND #239 ; AND MAY BE REMOVED IF YOU DO NOT
STA $D011 ; WANT SCREEN BLANKING
;
LDX #7 ;╙END A ╒├ COMMAND TO THE DRIVE,
JSR CHKOUT ; WHICH TELLS THE DRIVE TO BEGIN
LDA #"U" ; EXECUTING CODE AT $500, WHICH
JSR CHROUT ; IS WHERE THE FAST ROUTINE RESIDES
LDA #"C"
JSR CHROUT
LDA #13
JSR CHROUT
JSR CLRCHN
LDA #%00000111 ;├OMPUTER ALLOWS ├╠╦ AND ─┴╘┴ TO
STA CIA ; GO HIGH
LDY #255 ;─ELAY LOOP NECESSARY TO ALLOW
LDX #127 ; DRIVE CODE TO INITIALIZE ITSELF
- DEX ; AND ENTER MAIN LOOP
BNE -
DEY
BNE -
RTS
;
;╘HIS ROUTINE TELLS THE DRIVE THAT IS CURRENTLY EXECUTING
;THE FAST ROUTINES TO RELEASE THE SERIAL BUS. ╘HE FAST
;ROUTINES ARE DEACTIVATED, AND THE NORMAL ─╧╙ TAKES OVER
;IN THAT DRIVE.
;
;╔T IS NOT NECESSARY TO PASS THE DRIVE NUMBER TO THIS
;ROUTINE, AS ONLY ONE SERIAL DEVICE CAN BE ACTIVE AT
;ONCE. ╬OTE: ╬O REGISTERS ARE PRESERVED.
;
RELEASEF = *
;
SEI
LDA #0 ;╙END COMMAND 0 (DEACTIVATE) TO
JSR SENDF ; CURRENT DEVICE
CLI
;
LDA $D011 ;╘HESE THREE LINES REACTIVATE
ORA #16 ; THE TEXT SCREEN AND ARE
STA $D011 ; UNNECESSARY IF NOT BLANKED
;
LDA #7 ;├LOSE LOGICAL FILE TO KEEP THINGS
JMP CLOSE ; TIDY FOR NORMAL ╧╙
;
;╥┼┴─╞ READS A BLOCK FROM THE CURRENTLY ACTIVE DRIVE.
;┬EFORE CALLING THIS ROUTINE, THE TRACK (1-35) SHOULD BE
;STORED IN ╞╘╥┴├╦, AND THE SECTOR SHOULD BE STORED IN
;╞╙┼├╘╧╥. ╧N RETURN, THE DATA IN THAT BLOCK WILL BE
;IN ╞┴╙╘┬╒╞. ┴LSO, THE ACCUMULATOR WILL BE SET TO REFLECT
;THE ERROR STATUS OF THE DRIVE. ╨OSSIBLE VALUES:
;
; 0 = ╧╦ 8 = ╫RITE PROTECT ON
; 1 = ╧╦ 9 = ╫RONG HEADER CHKSUM
; 2 = ┬LOCK HEADER NOT FOUND ┴ = ─ATA BLOCK TOO LONG
; 3 = ╙YNC MARK NOT FOUND ┬ = ┬AD DISK ╔─
; 4 = ─ATA BLOCK NOT FOUND ─ = ╔NDEX HOLE NOT FOUND
; 5 = ┬AD DATA BLOCK CHECKSUM ┼ = ├ONTROLLER ERROR
; 6 = ╞ORMAT ERROR ╞ = ╬O DISK FOUND
; 7 = ╓ERIFY ERROR
;
;╙TATUS BITS WILL BE SET TO REFLECT THE VALUE IN .┴
;╬O REGISTERS ARE PRESERVED.
;
READF = *
;
SEI
LDA #1 ;╙END CODE 1 (READ BLOCK) TO DRIVE
JSR SENDF
LDA FTRACK ;╙END TRACK/SECTOR TO DRIVE
JSR SENDF
LDA FSECTOR
JSR SENDF
LDY #0 ;╥ECEIVE 256 BYTES THAT MAKE UP
- JSR GETF ; BLOCK FROM DRIVE
STA FASTBUF,Y
INY
BNE -
JSR GETF ;257TH BYTE IS A STATUS BYTE
CLI
ORA #0 ;╙ET STATUS FLAGS TO REFLECT .┴
RTS
;
;╫╥╔╘┼╞ SENDS THE 256 BYTES AT ╞┴╙╘┬╒╞ TO THE BLOCK WHOSE
;TRACK IS IN ╞╘╥┴├╦ AND WHOSE SECTOR IS IN ╞╙┼├╘╧╥. ╧N
;RETURN, .┴ WILL CONTAIN THE ERROR STATUS, AS DISCUSSED FOR
;THE ╥┼┴─╞ ROUTINE ABOVE. ╬O REGISTERS ARE PRESERVED.
;
WRITEF = *
;
SEI
LDA #2 ;╙END COMMAND 2 (WRITE BLOCK)
JSR SENDF
LDA FTRACK ;╙END TRACK/SECTOR TO DRIVE
JSR SENDF
LDA FSECTOR
JSR SENDF
LDY #0 ;╙END 256 BYTES TO DRIVE
- LDA FASTBUF,Y
JSR SENDF
INY
BNE -
JSR GETF ;╟ET ERROR STATUS FROM DRIVE
CLI
ORA #0 ;╙ET STATUS FLAGS TO REFLECT .┴
RTS
;
;╙┼╬─╞ SENDS A SINGLE BYTE (IN .┴) TO THE CURRENT FAST
;DRIVE. ╘HE CONVENTIAL SERIAL BUS COMMUNICATION ROUTINES
;ARE SLOW BECAUSE THEY SEND ONE BIT AT A TIME AND INCLUDE
;A LOT OF "HANDSHAKING" BETWEEN EACH BIT. ╘HESE ROUTINES
;ONLY HANDSHAKE AT THE BEGINNING OF EACH ┬┘╘┼. ╔N ADDITION
;╘╫╧ BYTES ARE SENT AT ONCE (VIA THE USE OF THE ├╠╦ LINE
;IN ADDITION TO ─┴╘┴ TO SEND BITS). ╙INCE THERE IS NO
;HANDSHAKING WHILE SENDING A BYTE, THE TIMING OF THE
;SENDING ROUTINE (IN THE COMPUTER) MUST MATCH THE TIMING
;OF THE RECEIVING ROUTINE (IN THE DRIVE) IN ORDER FOR
;A BYTE TO BE TRANSMITTED PROPERLY.
;
SENDF = *
;
- LDX $D012 ;╫AIT FOR ELECTRON GUN TO MOVE
CPX #48 ; OFF OF VISIBLE SCREEN. ╘HESE 3
BCS - ; LINES CAN BE REMOVED IF BLANKED
;
LDX #%00010111 ;┬RING ├╠╦ LINE LOW TO SIGNAL
NOP ; DRIVE THAT A BYTE IS ON ITS
NOP ; WAY. ╟IVE DRIVE SOME TIME (╬╧╨S)
NOP ; TO ENTER RECEIVE BYTE ROUTINE
NOP
NOP ;╙ERIAL PORT LINES ARE FOUND AT
STX CIA ; ├╔┴ LOCATION $──00 IN ├64
PHA
AND #3 ;╔SOLATE BITS 0 AND 1 AND USE
TAX ; TABLE TO DETERMINE PROPER VALUE
LDA FTABLE,X ; TO GIVE ├╠╦ AND ─┴╘┴ EACH A BIT
STA CIA
LDA $FF ;3-CYCLE DELAY
NOP ;╬╧╨ = 2 CYCLE DELAY
PLA ;╥ETRIEVE ORIGINAL BYTE
LSR ;╟ET BITS 2 AND 3
LSR
PHA
AND #3 ;╔SOLATE BITS AND SEND AS ├╠╦
TAX ; AND ─┴╘┴
LDA FTABLE,X
STA CIA
NOP
PLA ;╥EPEAT PROCEDURE FOR BITS 4 AND 5
LSR
LSR
PHA
AND #3
TAX
LDA FTABLE,X
STA CIA
NOP
PLA ;╥EPEAT PROCEDURE FOR BITS 6 AND 7
LSR
LSR
AND #3
TAX
LDA FTABLE,X
STA CIA
NOP ;╠ONG DELAY WHILE DRIVE PROCESSES
NOP ; LAST TWO BITS
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
LDA #%00000111 ;┬RING ├╠╦ AND ─┴╘┴ HIGH TO
STA CIA ; PREPARE FOR NEXT SEND/GET
RTS
;
;╥ECEIVE A BYTE FROM THE CURRENT FAST DRIVE. ╘HE BYTE
;WILL BE RETURNED IN THE ACCUMULATOR. ╬O REGISTERS ARE
;PRESERVED. ╙EE NOTES FOR ╙┼╬─╞ ABOVE.
;
GETF = *
;
LDA #64 ;╫AIT FOR ├╠╦ TO GO LOW, WHICH
- BIT CIA ; MEANS DRIVE IS READY TO SEND
BNE -
;
- LDA $D012 ;╫AIT FOR ELECTRON GUN TO MORE OFF
CMP #48 ;SCREEN. ╬OT NECESSARY IF BLANKING
BCS - ;IS BEING USED!
;
+ LDA #%00100011 ;┬RING ─┴╘┴ LOW AS A SIGNAL THAT
STA CIA ; COMPUTER IS READY TO RECEIVE
NOP ;╠ONG DELAY WHILE DRIVE PREPARES
NOP ; FIRST TWO BITS
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
LDA #%00000011 ;┴LLOW ├╠╦ AND ─┴╘┴ TO GO HIGH SO
STA CIA ; DRIVE HAS CONTROL OF THEM
LDX #4 ;╠OOP TO GET 4 PAIRS OF BITS
- LDA CIA ;╥EAD SERIAL BUS
ROL ;╥OLL TWO BITS OUT OF SERIAL BUS
ROR BVALUE ; INTERFACE REGISTER INTO STORAGE
ROL ; FOR CURRENT BYTE
ROR BVALUE
NOP
LDA $FF ;3 CYCLE DELAY
DEX
BNE -
LDA BVALUE ;╥ETURN WITH COMPLETE BYTE
RTS
;
;╘ABLE FOR FAST SEND ROUTINE (COMPUTER). ╘HIS TABLE IS USED
;TO CONVERT A BIT PAIR INTO THE NECESSARY VALUE TO STORE
;AT THE SERIAL BUS COMMUNICATION REGISTER. ├╠╦ TAKES ON THE
;VALUE OF THE LEAST SIGNIFICANT BIT AND ─┴╘┴ REPRESENTS THE
;═╙┬.
;
FTABLE .BYTE %00000111 ;┬IT PAIR 00
.BYTE %00010111 ;01
.BYTE %00100111 ;02
.BYTE %00110111 ;03
;
;----------------------------------------------------------
;╘HIS CODE WILL RESIDE IN DRIVE MEMORY
;----------------------------------------------------------
;
DRIVECODE = *
;
;╔N ORDER TO INSURE MAXIMUM COMPATIBILITY WITH VARIOUS
;1541 "CLONES," ONLY THE STANDARD MEANS OF INTERFACING WITH
;THE DRIVE CONTROLLER WAS USED, E.G. THE JOB LOOP. ╘HIS IS
;AN INTERRUPT-DRIVEN ROUTINE THAT PERFORMS THE MOST BASIC
;DRIVE FUNCTIONS (I.E. READING AND WRITING A BLOCK).
;
.OFF $0500 ;┬EGIN OFFSET CODING.
;
;╓╔┴ (╓ERSATILE ╔NTERFACE ┴DAPTOR) EQUATES
;
VIA1 = $1800 ;╔NTERFACE TO SERIAL BUS
VIA2 = $1C00 ;CONTROLS DRIVE ELECTRONICS
;
;╩OB LOOP INTERFACE LOCATIONS.
;
JOB = 0 ;╩OB TO BE EXECUTED/JOB STATUS
JOBTRACK = 6 ;╘RACK FOR CURRENT JOB
JOBSECTOR = 7 ;╙ECTOR FOR CURRENT JOB
JOBBUFFER = $300 ;┬UFFER USED BY JOB LOOP 0
;
;┌ERO-PAGE LOCATIONS IN DRIVE MEMORY USED FOR TEMPORARY
;STORAGE BY THESE ROUTINES.
;
BYTE = 44 ;┬YTE TO SEND/BYTE RECEIVED
FYTEMP = 45 ;╙TORAGE FOR ┘ REGISTER
;
;╘HIS ROUTINE INITIALIZES THE DRIVE FOR FAST COMMUNICATION.
;
SEI ;╠OCK OUT NORMAL INTERRUPTS
LDA VIA2 ;╘URN OFF THE DRIVE LIGHT
AND #$F7 ; (COSMETIC PURPOSES ONLY)
STA VIA2
LDY #127 ;╫AIT FOR COMPUTER TO GET READY
LDX #63
- DEX
BNE -
DEY
BNE -
;
;═AIN LOOP - ACCEPT THE FOLLOWING ONE-BYTE COMMAND CODES
;FROM THE COMPUTER:
;
; 0 = ╥ETURN TO NORMAL ─╧╙ 2 = ╫RITE A BLOCK
; 1 = ╥EAD A BLOCK
;
;├OMMANDS 1 AND 2 REQUIRE TWO MORE BYTES TO FOLLOW
;IMMEDIATELY: THE TRACK AND SECTOR FOR THE GIVEN OPERATION.
;
LOOP = *
;
JSR GET ;╫AIT FOR AND RETRIEVE COMMAND
CMP #1 ; NUMBER FROM COMPUTER. ╔F NOT
BNE LOOP2 ; COMMAND 1 (READ), BRANCH...
;
;├OMMAND #1: ╥EAD A BLOCK FROM SPECIFIED TRACK/SECTOR.
;╔F THERE ARE ERRORS, THE OPERATION WILL BE RETRIED SEVEN
;TIMES BEFORE AN ERROR CONDITION IS REPORTED TO THE
;COMPUTER.
;
JSR GET ;╟ET TRACK
STA JOBTRACK
JSR GET ;╟ET SECTOR
STA JOBSECTOR
LDA VIA2 ;╘URN DRIVE LIGHT ON DURING READ
ORA #8 ; OPERATION
STA VIA2 ; (COSMETIC PURPOSES ONLY)
LDA #7 ;7 ATTEMPTS BEFORE GIVING UP
STA BYTE
FRL LDA #$80 ;$80 = ╩OB TO READ A BLOCK
STA JOB
CLI ;┴LLOW INTERRUPT-DRIVEN JOB
- BIT JOB ; LOOP TO FUNCTION. ╫HEN VALUE
BMI - ; BECOMES POSITIVE, JOB IS
SEI ; FINISHED
LDA JOB ;╩╧┬ NOW CONTAINS ERROR STATUS
CMP #2 ;╔F ╧╦, SEND BYTES TO COMPUTER
BCC +
DEC BYTE ;╧THERWISE, TRY AGAIN
BNE FRL
+ LDA VIA2 ;╘URN DRIVE LIGHT OFF
AND #$F7 ; (COSMETIC PURPOSES ONLY)
STA VIA2
LDY #0 ;╙END 256 BYTES THAT MAKE UP
- LDA JOBBUFFER,Y ; BLOCK TO COMPUTER
JSR SEND
INY
BNE -
LDA JOB ;╙END ERROR STATUS TO COMPUTER
JSR SEND
JMP LOOP ;╥ETURN TO WAIT FOR NEXT COMMAND
;
;├ONTINUATION OF MAIN LOOP: IF NOT COMMAND #2 (WRITE BLOCK)
;THEN BRANCH...
;
LOOP2 CMP #2
BNE LOOP3
;
;├OMMAND #2: ╥ECEIVE A TRACK AND SECTOR, AS WELL AS 256
;BYTES FROM COMPUTER AND WRITE THEM TO DISK AT THE
;SPECIFIED TRACK AND SECTOR.
;
DDWRITE JSR GET ;╟ET TRACK
STA JOBTRACK
JSR GET ;╟ET SECTOR
STA JOBSECTOR
LDY #0 ;╥ECEIVE 256 BYTES FROM COMPUTER
- JSR GET ; AND STORE IN JOB BUFFER
STA JOBBUFFER,Y
INY
BNE -
LDA #7 ;7 ATTEMPTS BEFORE REPORTING ERROR
STA BYTE
FWL LDA #$90 ;$90 = ╩OB TO WRITE A SECTOR
STA JOB
LDA VIA2 ;╘URN ON DRIVE LIGHT
ORA #8 ; (COSMETIC PURPOSES ONLY)
STA VIA2
CLI ;┴LLOW INTERRUPT-DRIVEN JOB LOOP
- BIT JOB ; TO FUNCTION. ╓ALUE WILL BECOME
BMI - ; POSITIVE WHEN JOB IS FINISHED
SEI
LDA VIA2 ;╘URN OFF DRIVE LIGHT
AND #$F7 ; (COSMETIC PURPOSES ONLY)
STA VIA2
LDA JOB ;─ID JOB LOOP REPORT AN ERROR?
CMP #2
BCC + ; ╬O - REPORT ╧╦ STATUS TO COMPUTER
DEC BYTE ; ┘ES - TRY AGAIN
BNE FWL
+ JSR SEND ;╙END ERROR STATUS TO COMPUTER
JMP LOOP ;╥ETURN TO WAIT FOR NEXT COMMAND
;
;┴NY COMMAND OTHER THAN 1 OR 2 RESULTS IN TERMINATION OF
;THE FAST SERIAL ROUTINES AND RETURN TO NORMAL ─╧╙.
;
LOOP3 CLI
RTS
;
;╥ECEIVE A BYTE FROM THE COMPUTER USING THE FAST SERIAL
;PROTOCOL.
;
GET = *
;
LDA #0 ;┴LLOW ├╠╦ AND ─┴╘┴ TO GO HIGH
STA VIA1 ; TO GIVE COMPUTER CONTROL OF THEM
LDA #4
- BIT VIA1 ;╫AIT FOR ├╠╦ TO GO LOW
BEQ -
NOP ;╠ONG DELAY WHILE COMPUTER PREPARES
NOP ; FIRST 2 BITS TO SEND
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
LDA VIA1 ;╥EAD SERIAL BUS AND ISOLATE ├╠╦
AND #7 ; AND ─┴╘┴ INPUT LINES (BITS 2
TAX ; AND 1. ┬IT 1 IS ─┴╘┴ OUT)
LDA FTABLE1,X ;╠OOK UP PROPER BIT PAIR IN TABLE
STA BYTE
NOP ;╫AIT FOR NEXT 2 BITS TO BE PUT ON
NOP ; SERIAL BUS
NOP
NOP
NOP
LDA VIA1 ;╔SOLATE ├╠╦ AND ─┴╘┴ LINES AND
AND #7 ; USE TABLE TO LOOK UP BIT PAIR.
TAX
LDA FTABLE2,X
ORA BYTE ;├OMBINE BITS 2 AND 3 (JUST READ)
STA BYTE ; WITH BITS 0 AND 1 (ALREADY READ)
NOP
LDA $FF ;3-CYCLE DELAY
NOP
LDA VIA1 ;╥EPEAT PROCESS FOR BITS 4 AND 5
AND #7
TAX
LDA FTABLE3,X
ORA BYTE
STA BYTE
NOP
LDA $FF ;3-CYCLE DELAY
NOP
LDA VIA1 ;╥EPEAT PROCESS FOR BITS 6 AND 7
AND #7
TAX
LDA FTABLE4,X
ORA BYTE ;╫E NOW HAVE COMPLETE BYTE
RTS
;
;╙END A BYTE TO THE COMPUTER USING THE FASTER SERIAL
;PROTOCOL.
;
SEND = *
;
STA BYTE ;╙AVE BYTE
STY FYTEMP ;╨RESERVE ┘ REGISTER
LDA #%00001000 ;┬RING ├╠╦ LOW TO TELL COMPUTER
STA VIA1 ; THAT DRIVE IS READY TO SEND
LDA #1 ;╫AIT FOR ─┴╘┴ TO GO LOW, WHICH
- BIT VIA1 ; MEANS THAT COMPUTER IS READY
BEQ - ; TO RECEIVE
LDA BYTE ;╥ECALL BYTE TO BE SENT
LDY #4 ;╠OOP TO SEND 4 PAIRS OF BITS
- STA BYTE ;╙AVE CURRENT BYTE VALUE
AND #3 ;╔SOLATE BITS 0 AND 1 AND USE
TAX ; TABLE TO LOOK UP PROPER VALUE
LDA FTABLE5,X ; TO STORE IN COMMUNICATIONS
STA VIA1 ; REGISTER TO REFLECT THOSE BITS
LDA BYTE ;╥ECALL CURRENT BYTE
LSR ;╙HIFT BYTE RIGHT SO THAT BITS 2
LSR ; AND 3 BECOME BITS 0 AND 1, ETC
DEY
BNE - ;╥ETURN FOR REMAINING BIT PAIRS
LDY FYTEMP ;╟ET BACK ORIGINAL ┘ REGISTER VALUE
NOP ;╫AIT FOR COMPUTER TO PROCESS LAST
NOP ; BIT PAIR
NOP
NOP
NOP
NOP
LDA #0 ;┬RING ├╠╦ AND ─┴╘┴ HIGH TO GIVE
STA VIA1 ; CONTROL OF SERIAL BUS TO COMPUTER
RTS
;
;╘ABLES FOR USE BY DRIVE RECEIVE ROUTINE. ╙INCE THE ├╠╦
;AND ─┴╘┴ INPUT LINES ARE NOT TWO CONSECUTIVE BITS, IT
;IS NECESSARY TO ISOLATE AN EXTRA BIT, WHICH MEANS THAT
;THERE ARE 8 POSSIBLE VALUES, WHICH YIELD ONLY 4 DIFFERENT
;BIT PAIRS. ┴ SEPARATE TABLE IS USED FOR EACH BIT PAIR
;RECEIVED, IN ORDER TO EASILY CONSTRUCT A COMPLETE BYTE.
;╞╘┴┬╠┼1 HANDLES BITS 0 AND 1, ╞╘┴┬╠┼2 HANDLES BITS 2 AND3,
;AND SO ON.
;
FTABLE1 .BYTE %00,%10,%00,%10
.BYTE %01,%11,%01,%11
FTABLE2 .BYTE %0000,%1000,%0000,%1000
.BYTE %0100,%1100,%0100,%1100
FTABLE3 .BYTE %000000,%100000,%000000,%100000
.BYTE %010000,%110000,%010000,%110000
FTABLE4 .BYTE %00000000,%10000000,%00000000,%10000000
.BYTE %01000000,%11000000,%01000000,%11000000
;
;╘ABLE USED BY DRIVE SEND ROUTINE. ╘HIS TABLE TRANSLATES
;A PAIR OF BITS INTO THE PROPER VALUE TO STORE AT THE
;SERIAL COMMUNICATIONS REGISTER (AT $1800) TO MAKE THE ├╠╦
;AND ─┴╘┴ LINES REFLECT THOSE BITS.
;
FTABLE5 .BYTE %00001010
.BYTE %00001000
.BYTE %00000010
.BYTE %00000000
;
;┼ND OF DRIVE CODE
;
.OFE ;┼NDS OFFSET CODING
;
ENDDRIVECODE = * ;═ARKS END OF DRIVE CODE IN
;RELATION TO REGULAR PROGRAM
;
.END